package cn.itsource.user.dto;

import cn.itsource.basic.util.MD5Utils;
import cn.itsource.basic.util.StrUtils;
import cn.itsource.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * <p>@Description:方法的用途</p>
 * <p>@param [entId, roleId, type, deptId, level, personStaffIds, latelyUserId] 参数列表</p>
 * <p>@return 返回值</p>
 * <p>@throws 抛出异常类型</p>
 * <p>@author 方法作者</p>
 * <p>@date 创建时间</p>
 */
@Data
public class WechatBinderDto {

    @NotBlank(message = "accessToken不能为空！")
    private String accessToken;
    @NotBlank(message = "openId不能为空！")
    private String openId;
    @NotBlank(message = "phone不能为空！")
    private String phone;
    @NotBlank(message = "verifyCode不能为空！")
    private String verifyCode;

    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 盐值 + 密码
        String pw = MD5Utils.encrypByMd5(salt + "1");
        return User
                .builder()
                .createtime(new Date())
                .salt(salt)
                .password(pw)
                .state(1)
                .phone(this.phone)
                .username(this.phone)
                .build();

    }
}
